package Day17;

import javax.imageio.metadata.IIOMetadataFormatImpl;
import java.lang.module.ResolutionException;

public class BubbleSort {
    public static void main(String[] args) {
        //冒泡排序
        //化繁为简，先死后活
       /* int[] arr = {99,77,5,58,6755,89};
        for(int i = 0; i < arr.length - 1; i++){  //要排多少轮
            int temp = 0;
            for(int j = 0; j < arr.length - 1 - i; j++){  //要比较多少次
                if(arr[j] > arr[j + 1]){
                    temp = arr[j + 1];
                    arr[j + 1] = arr[j];
                    arr[j] = temp;
                }
            }
            System.out.println("\n=====第一次排序======");
            for (int i1 = 0; i1 < arr.length; i1++) {
                System.out.print(arr[i1] + "\t");
            }
        }
*/

        int[] arr = {5,4,3,2,1};
        for(int i = 0; i < arr.length -1; i++){
            int temp = 0;
            for(int j = 0; j < arr.length - 1 - i;j++){
                if(arr[j]  >= arr[ j + 1]){
                    temp = arr[j + 1];
                    arr[j + 1] = arr[j];
                    arr[j] = temp;
                }
            }
            System.out.println("\n=====第"+(i + 1)+"次排序");
            for (int i1 = 0; i1 < arr.length; i1++) {
                System.out.print(arr[i1] + "\t");
            }
        }
     }
}
